package com.one.controller;

import com.one.annotation.RequestPermission;
import com.one.bean.ConsigneeInfo;
import com.one.bean.User;
import com.one.service.UserInfoService;
import com.one.util.RequestReturn;
import com.one.vo.UpUserVo;
import com.one.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author ShiWen
 * @date 2022/1/19 17:17
 * @Version 1.0
 * @Description TODO 用户个人信息
 */
@RestController
@Api(tags = "E.用户个人信息操作")
@Slf4j
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;
    /**
     * @description 查询用户信息
     * @author ShiWen
     * @date 2022/1/19 9:45
     */
    @ApiOperation(value = "查询用户信息",notes = "查看当前登录的用户信息")
    @RequestPermission
    @GetMapping("/getUser")
    public RequestReturn<UserVo> queryUser(){
        return userInfoService.queryUser();
    }

    /**
     * @description 修改密码
     * @author ShiWen
     * @date 2022/1/19 10:11
     */
    @ApiOperation(value = "修改密码" ,notes = "无需登录也可操作，需要发送手机验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "用户的手机号"),
            @ApiImplicitParam(name = "newPwd", value = "新密码"),
            @ApiImplicitParam(name = "auth", value = "收到的验证码")
    })
    @PostMapping("/updatePwd")
    public RequestReturn<String> updatePwd(String phone,String newPwd,String auth){
        return userInfoService.updatePwd(phone, newPwd, auth);
    }
    /**
     * @description 修改个人信息
     * @author ShiWen
     * @date 2022/1/19 13:48
     */
    @ApiOperation(value = "修改个人信息",notes = "填写需要修改的信息，登录才可操作")
    @RequestPermission
    @PostMapping("/updateUserInfo")
    public RequestReturn<String> updatePwd(@RequestBody UpUserVo user){
        return userInfoService.updatePwd(user);
    }
    /**
     * @description 添加个人收货信息
     * @author ShiWen
     * @date 2022/1/19 14:26
     */
    @ApiOperation(value = "添加个人收货信息")
    @RequestPermission
    @PostMapping("/insertConsignee")
    public RequestReturn<String> insertConsignee(@RequestBody ConsigneeInfo consigneeInfo){
        log.info("新增的个人收获信息：{}",consigneeInfo);
        return userInfoService.insertConsignee(consigneeInfo);
    }
    /**
     * @description 删除地址信息
     * @author ShiWen
     * @date 2022/1/19 15:13
     */
    @ApiImplicitParam(name = "consigneeId", value = "用户地址的id")
    @ApiOperation(value = "删除地址信息" ,notes = "根据地址的id删除")
    @RequestPermission
    @PostMapping("/delConsignee")
    public RequestReturn<String> delConsigneeById(Integer consigneeId){
        return userInfoService.delConsigneeById(consigneeId);
    }
    /**
     * @description 设置地址为默认
     * @author ShiWen
     * @date 2022/1/19 15:24
     */
    @ApiOperation(value = "设置地址为默认")
    @RequestPermission
    @GetMapping("/setDefault")
    public RequestReturn<String> setDefaultAddress(Integer consigneeId){
        return userInfoService.setDefaultAddress(consigneeId);
    }
    /**
     * @description 查询用户的所有收货地址
     * @author ShiWen
     * @date 2022/1/19 16:04
     */
    @ApiOperation(value = "查询用户的所有收货地址")
    @RequestPermission
    @GetMapping("/queryConsignee")
    public RequestReturn<List<ConsigneeInfo>> queryConsignee(){
        return userInfoService.queryConsignee();
    }

    /**
     * @description 查询用户默认收货地址
     * @author ShiWen
     * @date 2022/1/19 16:04
     */
    @ApiOperation(value = "查询用户默认收货地址")
    @RequestPermission
    @GetMapping("/defaultConsignee")
    public RequestReturn<ConsigneeInfo> defaultConsignee(){
        return userInfoService.defaultConsignee();
    }
}

